const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const router = require('./router')
const errorHandler = require('./middleware/error-handler')
require('./model')

// 实例化express
const app = express()
// 请求日志中间件
app.use(morgan('dev'))
// 处理请求数据的中间件
app.use(express.json())
// 解决跨域 中间件
app.use(cors())

// 挂载路由
app.use('/api', router)

// 挂载统一处理服务端错误中间件
app.use(errorHandler())

app.listen(3000, () => {
  console.log(`Server is running at http://localhost:3000`)
})
